package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.MaterieListOriginal.MaterieListContent;
import com.isunland.managesystem.utils.NumberUtil;
import java.util.List;

public class MaterieLisAdapter extends ArrayAdapter<MaterieListContent> {
  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-01-12 16:53:02 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvMaterielName;//物料名称
    public final TextView tvMaterielNum;//数量
    public final TextView tvUnitPrice;//单价

    private ViewHolder(LinearLayout rootView, TextView tvMaterielName, TextView tvMaterielNum,
        TextView tvUnitPrice) {
      this.rootView = rootView;
      this.tvMaterielName = tvMaterielName;
      this.tvMaterielNum = tvMaterielNum;
      this.tvUnitPrice = tvUnitPrice;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvMaterielName = (TextView) rootView.findViewById(R.id.tv_materiel_name);
      TextView tvMaterielNum = (TextView) rootView.findViewById(R.id.tv_materiel_num);
      TextView tvUnitPrice = (TextView) rootView.findViewById(R.id.tv_unit_price);
      return new ViewHolder(rootView, tvMaterielName, tvMaterielNum, tvUnitPrice);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_materie_list, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    MaterieListContent item = getItem(position);
    //初始化控件

    vh.tvMaterielName.setText(item.getMaterialName());
    //		vh.tvTypeMainProduct.setText(item.getsInbillCode());
    vh.tvUnitPrice.setText(String.valueOf(item.getMoutPrice()));
    //		vh.tvOutCode.setText(item.getMoutNumber());
    vh.tvMaterielNum.setText(NumberUtil.numberBigToString(item.getMoutNumber()));

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public MaterieLisAdapter(Context context, List<MaterieListContent> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public MaterieLisAdapter(Context context, MaterieListContent[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
